<?php
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
?>

<form action="?r=demo/index_do" method="post">
    <div class="form-group">
        <label for="exampleInputEmail1">邮箱</label>
        <input type="email" class="form-control" name="email" id="email" placeholder="请输入邮箱" onblur="fun2()">
    </div>
    <div class="form-group">
        <label for="exampleInputPassword1">用户名</label>
        <input type="text" class="form-control" name="name" id="name" placeholder="请输入用户名" onblur="fun()">
    </div>
    <div class="form-group">
        <label for="exampleInputPassword1">密码</label>
        <input type="password" class="form-control" name="pwd" id="pwd" placeholder="请输入密码" onblur="fun1()">
    </div>
    <div class="form-group">
        <label for="exampleInputPassword1">手机号</label>
        <input type="text" class="form-control" name="tel" id="tel" placeholder="请输入手机号">
    </div>

    <input type="hidden" name="_csrf" value="<?php echo Yii::$app->request->csrfToken?>">
    <button type="submit" class="btn btn-default">提交</button>
</form>
<script>
    function fun()
    {
        var name = document.getElementById("name").value
        var verify = /^\w{2,20}$/g
        if(!verify.test("name"))
        {
            alert("请输入用户名，格式为2-20个字符，可以为字母，数字，下划线")
        }
    }

    function fun1()
    {
        var pwd = document.getElementById("pwd").value
        var verifys = /^\d{6,32}$/
        if(verifys.test("pwd"))
        {
            alert("密码格式为6-32个数字")
        }
    }

    function fun2()
    {
        var pwd = document.getElementById("email").value
        var verify1 = /^([a-zA-Z][0-9]\w+@[a-zA-Z0-9]+\.[a-zA-Z0-9])$/
        if(verify1.test("email"))
        {
            alert("邮箱格式有问题")
        }
    }
</script>
